package com.example.yan_music.presenter;

import android.util.Log;

import com.example.yan_music.base.presenter.BasePresenter;
import com.example.yan_music.bean.wangyi.SongDetail;
import com.example.yan_music.bean.wangyi.SongListDetail;
import com.example.yan_music.contract.IListDetailContract;
import com.example.yan_music.event.PlayListInfoEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class IListDetailPresenterImp extends BasePresenter<IListDetailContract.View> implements IListDetailContract.Presenter{
    private static final String TAG = "IListDetailPresenterImp";

    @Override
    public void getPlayListDetail(long songListId) {
        mModel.getPlayListDetail(songListId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<SongListDetail>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        Log.d(TAG, "onSubscribe: asdasdasdasdasd");
                    }

                    @Override
                    public void onNext(SongListDetail songListDetail) {
                        if(songListDetail.getCode() == 200){
                            SongListDetail.PlaylistBean playlistBean = songListDetail.getPlaylist();
                            Log.d(TAG, "onNext: " + playlistBean.getCoverImgUrl());
                            Log.d(TAG, "onNext: " + playlistBean.getName());
                            mView.setTrackIds(songListDetail.getPlaylist());
                        }else {
                            Log.d(TAG, "onNext: 请求失败");
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {
                        Log.d(TAG, "onComplete: 请求歌单详情完成");
                    }
                });
    }

    @Override
    public void getSongDetail(String ids) {
        mModel.getSongDetail(ids)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<SongDetail>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(SongDetail songDetail) {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
